jade.onto
Class DefaultOntology

java.lang.Object
  |
  +--jade.onto.DefaultOntology

public final class DefaultOntology
extends java.lang.Object
implements Ontology

A simple implementation of the Ontology interface. Instances of this class keeps all the ontology data in memory, and don't support an external archive format.

Author:
Giovanni Rimassa - Universita` di Parma

Fields inherited from interface jade.onto.Ontology
ANY_SLOT, ANY_TYPE, BINARY_TYPE, BOOLEAN_TYPE, BYTE_TYPE, CHARACTER_TYPE, DATE_TYPE, DOUBLE_TYPE, FLOAT_TYPE, FRAME_SLOT, INTEGER_TYPE, LONG_TYPE, M, NAME_OF_SEQUENCE_FRAME, NAME_OF_SET_FRAME, O, PRIMITIVE_SLOT, SEQUENCE_SLOT, SET_SLOT, SHORT_TYPE, STRING_TYPE
 
Constructor Summary
DefaultOntology()
          Default constructor.
 
Method Summary
 void addRole(java.lang.String roleName, SlotDescriptor[] slots)
          Adds a new role to this ontology, without a user defined Java class to represent it.
 void addRole(java.lang.String roleName, SlotDescriptor[] slots, java.lang.Class newClass)
          Adds a new role to this ontology, with a user defined Java class to represent it.
 void check(Frame f)
          Checks whether a given frame is correct with respect to this ontology.
 void check(java.lang.Object o, java.lang.String roleName)
          Checks whether a given Java object is correct with respect to the given role in this ontology.
 java.lang.Object create(Frame f)
          Creates an object, starting from a given frame.
 Frame createFrame(java.lang.Object o, java.lang.String roleName)
          Creates a frame from a given Java Object representing an instance of a given role.
 List createObject(List v)
          Creates a List of Java objects from the given list of frame.
 void fromMetaOntologyRepresentation(AnOntology o)
          Initialize this ontology based on the passed meta-ontology
 java.lang.String fromSL0String(java.lang.String str)
          This method initialized this ontology object on the basis of its representation as an SL-0 expression.
 java.lang.Class getClassForRole(java.lang.String roleName)
          Provides the Java class associated with this ontological role.
 java.lang.String getRoleName(java.lang.Class c)
           
 SlotDescriptor[] getSlots(java.lang.String roleName)
          Get the descriptions for all the slots that define the structure of a given ontological role.
 List getVocabulary()
           
 boolean isRole(java.lang.String roleName)
          Checks whether a given string is the name of a role in this ontology.
 void joinOntology(Ontology o)
          Adds to this ontology all roles included into another ontology
 AnOntology toMetaOntologyRepresentation(java.lang.String ontologyName)
          Return an object representing this ontology in terms of the JADE-Meta-Ontology and that is suitable to be encoded as a String and, for instance, become the content of an ACLMessage.
 java.lang.String toSL0String(java.lang.String ontologyName)
          Writes the ontology represented by this Ontology object as an SL-0 expression.
 java.lang.String toString()
          Return a String representing this ontology Object by calling the method toSL0String() and catching any exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultOntology

public DefaultOntology()
Default constructor.
Method Detail

addRole

public void addRole(java.lang.String roleName,
                    SlotDescriptor[] slots)
             throws OntologyException
Adds a new role to this ontology, without a user defined Java class to represent it.
Specified by:
addRole in interface Ontology
See Also:
Ontology.addRole(String roleName, SlotDescriptor[] slots)

addRole

public void addRole(java.lang.String roleName,
                    SlotDescriptor[] slots,
                    java.lang.Class newClass)
             throws OntologyException
Adds a new role to this ontology, with a user defined Java class to represent it.
Specified by:
addRole in interface Ontology
See Also:
Ontology.addRole(String roleName, SlotDescriptor[] slots, Class c)

joinOntology

public void joinOntology(Ontology o)
                  throws OntologyException
Adds to this ontology all roles included into another ontology
Specified by:
joinOntology in interface Ontology
Parameters:
o - The Ontology object whose roles will be added
See Also:
Ontology.joinOntology(Ontology o)

createObject

public List createObject(List v)
                  throws OntologyException
Creates a List of Java objects from the given list of frame.
Specified by:
createObject in interface Ontology
See Also:
Ontology.createObject(List v)

createFrame

public Frame createFrame(java.lang.Object o,
                         java.lang.String roleName)
                  throws OntologyException
Creates a frame from a given Java Object representing an instance of a given role.
Specified by:
createFrame in interface Ontology
See Also:
Ontology.createFrame(Object o, String roleName)

check

public void check(Frame f)
           throws OntologyException
Checks whether a given frame is correct with respect to this ontology.
Specified by:
check in interface Ontology
See Also:
Ontology.check(Frame f)

check

public void check(java.lang.Object o,
                  java.lang.String roleName)
           throws OntologyException
Checks whether a given Java object is correct with respect to the given role in this ontology.
Specified by:
check in interface Ontology
See Also:
Ontology.check(Object o, String roleName)

isRole

public boolean isRole(java.lang.String roleName)
               throws OntologyException
Checks whether a given string is the name of a role in this ontology.
Specified by:
isRole in interface Ontology
See Also:
Ontology.isRole(String roleName)

getSlots

public SlotDescriptor[] getSlots(java.lang.String roleName)
                          throws OntologyException
Get the descriptions for all the slots that define the structure of a given ontological role.
Specified by:
getSlots in interface Ontology
See Also:
Ontology.getSlots(String roleName)

getRoleName

public java.lang.String getRoleName(java.lang.Class c)
                             throws OntologyException
Specified by:
getRoleName in interface Ontology
Returns:
the name of the role represented by the passed class as registered in this ontology
Throws:
OntologyException - if no role is found for this class
See Also:
Ontology.getRoleName(Class c)

getVocabulary

public List getVocabulary()
Specified by:
getVocabulary in interface Ontology
Returns:
a List including the names of all the roles in the ontology, i.e. the Vocabulary used by the ontology
See Also:
Ontology.getVocabulary()

getClassForRole

public java.lang.Class getClassForRole(java.lang.String roleName)
Provides the Java class associated with this ontological role. This class is usually the class used by the create() method to instantiate objects. A useful technique is returning an interface or an abstract class, while using concrete subclasses to create objects.
Specified by:
getClassForRole in interface Ontology
Parameters:
a - string representing the name of the ontological role
Returns:
the Java class that plays this ontological role (e.g. DFAgentDescription.class

fromSL0String

public java.lang.String fromSL0String(java.lang.String str)
                               throws Codec.CodecException,
                                      OntologyException
Description copied from interface: Ontology
This method initialized this ontology object on the basis of its representation as an SL-0 expression. This expression is based on the JADE-Meta-Ontology encoded in the package jade.onto.JADEMetaOntology
Specified by:
fromSL0String in interface Ontology
See Also:
Ontology.fromSL0String(String)

fromMetaOntologyRepresentation

public void fromMetaOntologyRepresentation(AnOntology o)
                                    throws OntologyException
Description copied from interface: Ontology
Initialize this ontology based on the passed meta-ontology
Specified by:
fromMetaOntologyRepresentation in interface Ontology
See Also:
Ontology.fromMetaOntologyRepresentation(AnOntology)

toString

public java.lang.String toString()
Return a String representing this ontology Object by calling the method toSL0String() and catching any exception. Notice that this method ignores the name of the ontology and, therefore, the method toSL0String() should be preferred, instead.
Overrides:
toString in class java.lang.Object
Returns:
the String representing this ontology, or null if any exception occurs.

toMetaOntologyRepresentation

public AnOntology toMetaOntologyRepresentation(java.lang.String ontologyName)
Description copied from interface: Ontology
Return an object representing this ontology in terms of the JADE-Meta-Ontology and that is suitable to be encoded as a String and, for instance, become the content of an ACLMessage.
Specified by:
toMetaOntologyRepresentation in interface Ontology
See Also:
Ontology.toMetaOntologyRepresentation(String)

toSL0String

public java.lang.String toSL0String(java.lang.String ontologyName)
                             throws OntologyException
Writes the ontology represented by this Ontology object as an SL-0 expression.
Specified by:
toSL0String in interface Ontology
See Also:
Ontology.toSL0String(String)

create

public java.lang.Object create(Frame f)
                        throws OntologyException
Description copied from interface: Ontology
Creates an object, starting from a given frame. This method can just create the object ignoring its argument, or it can use the frame to select the concrete class to instantiate.
Specified by:
create in interface Ontology
Tags copied from interface: Ontology
Parameters:
f - A frame containing initialization data for the object.
Returns:
A Java object, instance of the proper class (either the class returned by getClassForRole(), or one of its subclasses).